<?php
class member extends ujn_controller {
	var $auto_render = false;
	//http://50.22.168.2/dice/_hookdoor/_datadoor.php?member-get_user || p=facebook&uid=1152
	
	//获取用户信息
	public function get_user(){
		$data = array(
			'flag' => 1,
			'lists' => isset($_POST['uid']) ? 
							mdl_member_info::getInstance()->getMember((int)$_POST['uid'])
								: array(),
		);
		echo json_encode( $data );
	}
	
	//加钱
	public function addMoney(){
		$data = array(
			'flag' => mdl_member_winlog::getInstance()->addWin($_POST['uid'], mdl_member_winlog::INTER_ADD, 0, $_POST['money'], '', '', 1) ? '1' : '0'
		);
		echo json_encode( $data );
	}
	
	//减钱
	public function cutMoney(){
		$data = array(
			'flag' => mdl_member_winlog::getInstance()->addWin($_POST['uid'], mdl_member_winlog::INTER_CUT, 1, $_POST['money'], '', '', 1) ? '1' : '0'
		);
		echo json_encode( $data );
	}
	
	// 获取分表表名
	function get_dbtables() {
		$prefix = isset($_REQUEST['prefix']) ? $_REQUEST['prefix'] : '';
		$_data = array();
		if(!empty($prefix)) {
	
			switch ($prefix) {
				case 'logmember':
				case 'logtable':
				case 'winlog':
					$_db = mdl_member_info::getInstance()->getDB();
					$tmp = $_db->getAll('show tables;');
					foreach($tmp as $val) {
						list($null, $null, $dbname) = explode('_', array_shift(array_keys($val)));
						$val = current($val);
						if ( strstr( $val, $prefix ) ) {
							$_data[] = "`$dbname`.`$val`";
						}
					}
				;
				break;
			}
		}
		$_data = empty($_data) ? array(
			'msg' => 'unfound tables.'
		) : $_data;
		$data = array(
			'flag' => 1,
			'lists' => $_data
		);
		echo json_encode($data);
	}
	
	//分表明细
	function get_dbwinlogdetail() {
		$tbl = isset($_REQUEST['tbl']) ? $_REQUEST['tbl'] : '';
		$uid = isset($_REQUEST['uid']) ? $_REQUEST['uid'] : '';
		$_data = array();
		if(!empty($tbl)) {
			list($null, $type, $null) = array_pad(explode('_', $tbl), 3, '');
			switch ($type) { // 这里要做正则匹配
				case 'winlog': $_data = mdl_member_winlog::getInstance()->getDataByUid($uid, $tbl); break;
	//			case 'logtable': break;
			}
		}
		$_data = empty($_data) ? array(
			'msg' => 'unfound details.'
		) : $_data;
		
		$data = array(
			'flag' => 1,
			'lists' => $_data
		);
		echo json_encode($data);
	}
	
	//在线状态
	function get_status(){
		$d = mdl_global_online::getInstance()->getLastByLevel('0');
		$data = array(
			'flag' => 1,
			'lists' => array( 'online' => $d['logall'], 'play' => $d['logplay'] ),
		);
		echo json_encode( $data );
	}	
}